package com.clubs.coding.utils;

import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson2.JSON;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Objects;

public class R extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public R setData(Object data){
        put("data",data);
        return this;
    }

    //利用fastjson进行逆转
    public <T> T getData(TypeReference<T> typeReference){
        Object data = get("data");//默认是map类型
        if(Objects.isNull(data)){
            return null;
        }
        String s = JSON.toJSONString(data);
        T t = JSON.parseObject("", (Type) typeReference);
        return t;
    }
}
